package com.baosight.sczx.zm.cl.service;

import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.User;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.zm.cl.domain.ZMCLRoundcheckWorknote;

/**
 * <p>Title: ServiceZMCL10.java</p>
 * <p>Description: 巡检工单反馈的服务类</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张小飞
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-13 下午02:53:16  张小飞  Create
 *</pre>
 */
public class ServiceZMCL10 extends ServiceEPBase {
	
	/**
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCL20</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-3-30下午03:04:27 张小飞
	 * </p>
	 *
	*/
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		EiInfo outInfo = null;
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		outInfo = this.query(inInfo);
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cl.noteSource", "cmes.cl.noteSourceInqu", true));//查询区：工单来源
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cl.noteSource"));//反馈：工单来源
		outInfo.addBlock(getSecurityPath());//巡检路线
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cl.department", "orgCode", "orgName", false));//责任单位
		outInfo.addBlock(User.getInstance().getConstructionStaff("cmes.cl.responsibilityPeople", "empCode", "empName", false));//巡检人
		
		return outInfo;
	}

	/**
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCL20</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-3-30下午03:04:27 张小飞
	 * </p>
	 *
	*/
	@Override
	public EiInfo query(EiInfo inInfo) {
		//默认按工单日期正序显示所有发单状态的巡检人为当前登录用户的巡检工单
		StaticTools.setQueryParameters(inInfo, "initFeedBack", "yes", true);
		StaticTools.setQueryParameters(inInfo, "fdResponsibilityPeople", UserSession.getUserId(), true);
		
		EiInfo outInfo = super.query(inInfo, "ZMCLRoundcheckWorknote.queryFeedback", new ZMCLRoundcheckWorknote());
		return outInfo;
	}

	/**
	 * <p>Function: update</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCL20</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-3-30下午03:04:27 张小飞
	 * </p>
	 *
	*/
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo outInfo = super.update(inInfo, "ZMCLRoundcheckWorknote.update");
		return outInfo;
	}
	
	
	/**
	 * <p>Function: getSecurityPath</p>
	 * <p>Description: 获取巡检路线的block</p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-3-29下午05:00:26 张小飞
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private EiBlock getSecurityPath() {
		
		EiBlock block = new EiBlock("cmes.cl.securityPath");

		EiColumn eiColumn = new EiColumn("fdKeyId");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("fdPathName");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map> _list = dao.query("ZMCLSecurityPath.queryInterface", null);

		block.setRows(_list);
		return block;
	}
	
}
